home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 568 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.2 KB  |  77 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: nathan@pact.srf.ac.uk (Nathan Sidwell)
  3. Newsgroups: comp.std.c++
  4. Subject: Base class access specifiers
  5. Date: 27 Feb 1996 18:54:36 GMT
  6. Organization: Inmos
  7. Sender: usenet@ncs.bris.ac.uk (Usenet news owner)
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <DnG4r9.4rr@uns.bris.ac.uk>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. X-Nntp-Posting-Host: talisker.pact.srf.ac.uk
  13. X-Newsreader: TIN [version 1.2 PL2]
  14. Apparently-To: comp-std-c++@britain.eu.net
  15. Content-Length: 1372
  16. X-Lines: 50
  17. Originator: clamage@taumet
  18.  
  19. I'm having problems determining if the following is legal or not,
  20. -snip
  21. class A {
  22. protected:
  23.   int member;
  24.   void func(A){};
  25. };
  26.   
  27. class B : protected A {
  28.   void func(B arg) {   
  29.     A::func(A(arg));      // ok
  30.   };
  31. };
  32.   
  33. class C : protected B {
  34.   void func(C arg) {   
  35.     A::func(A(arg));      // failed
  36.   };
  37. };  
  38. -snip
  39.  
  40. I think that the line marked 'failed' is the same as the line marked 'ok'.
  41.  
  42. However g++ 2.7.2 reports
  43. foo.cc: In method `void C::func(class C)':
  44. foo.cc:15: fields of `const A' are inaccessible in `C' due to private
  45.                                 inheritance
  46. foo.cc:5: in passing argument 1 of `A::A(const A &)'
  47. foo.cc:15: in conversion to type `A'
  48.  
  49. and cfront says,
  50. "foo.cc", line 15: error: cast: C* -> base A*; protected base class
  51. "foo.cc", line 15: error:  object or pointer missing for A::func() of type
  52.                                 void A::(A)
  53.  
  54. SGI CC accepts the code.
  55.  
  56. As far as I can see section 11.2 of the draft standard can be applied
  57. recursively to determine the access to A's members in C. This would make
  58. the two lines have the same meaning.
  59.  
  60. Where am I going wrong, or are g++ and cfront confused?
  61.  
  62. nathan
  63.  
  64. --
  65. Nathan Sidwell                         Holder of the Xmris home page
  66. Chameleon Architecture Group at SGS-Thomson, formerly Inmos
  67. http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
  68. nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
  69.  
  70.  
  71. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  72.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  73.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  74.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  75.   Comments? mailto:std-c++-request@ncar.ucar.edu
  76. ]
  77.